<template>
    <section>
        <!--列表展示-->
        <el-table :data="roles" highlight-current-row v-loading="listLoading"
                  style="width: 100%;">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column type="index">
            </el-table-column>
            <el-table-column prop="username" label="用户" sortable>
            </el-table-column>
            <el-table-column prop="name" label="角色名" sortable>
            </el-table-column>
            <el-table-column prop="sn" label="描述" sortable>
            </el-table-column>
            <el-table-column label="操作">
                <template scope="scope">
                    <el-button size="small" @click="handleEdit(scope.$index, scope.row)">分配角色</el-button>
                </template>
            </el-table-column>
        </el-table>


        <!--添加框-->
        <el-dialog title="驳回" :visible.sync="dialogFormVisible">

            <el-form :model="addForm" ref="addForm">
                <el-form-item label="角色" :label-width="formLabelWidth">
                    <el-select v-model="addForm.type" placeholder="请选择">
                        <el-option label="超级管理员" value="1"></el-option>
                        <el-option label="角色管理员" value="2"></el-option>
                        <el-option label="人事经理" value="4"></el-option>
                        <el-option label="市场部门" value="10"></el-option>
                        <el-option label="开发部" value="11"></el-option>
                        <el-option label="测试部" value="13"></el-option>
                    </el-select>
                </el-form-item>

            </el-form>

            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="sumbit('addForm')">确 定</el-button>
            </div>
        </el-dialog>

        <!--工具条-->
        <el-col :span="24" class="toolbar">
            <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="pageSize"
                           :total="total" style="float:right;">
            </el-pagination>
        </el-col>
    </section>
</template>

<script>

    export default {
        data() {


            return {
                id: "",
                rolename: "",
                formLabelWidth: "",
                //是否打开对话框
                dialogFormVisible: false,
                title: "",
                //选中多少行
                sels: "",
                //部门列表信息展示
                roles: [],
                localPage: 1,
                pageSize: 5,
                total: 0,
                //页面加载转圈圈
                listLoading: false,
                addForm: {
                    type: '',
                },
            }
        },
        methods: {
            //当前页改变
            handleCurrentChange(val) {
                this.localPage = val
                this.loadRoles()
            },
            sumbit() {
                let parms = {
                    id: this.id,
                    roleId: this.addForm.type
                }
                console.log(parms)
                this.$http.post("/role/addEmpRoles", parms).then(res => {
                    this.loadRoles()
                    this.dialogFormVisible = false
                }).catch()
            },
            //显示编辑界面
            handleEdit: function (index, row) {
                this.dialogFormVisible = true;
                this.id = row.id
            },

            // 加载部门列表,并切分页
            loadRoles() {
                // console.log("aaaaa")
                let param = {
                    "localPage": this.localPage,
                    "pageSize": this.pageSize,
                }
                this.$http.post("/role/queryEmpRoles", param).then(res => {
                    console.log(res)
                    let {data, totals} = res.data
                    this.roles = data
                    this.total = totals
                }).catch()
            },


        }, mounted() {
            this.loadRoles()
        }

    }


</script>
<style scoped>

</style>